﻿using LdtJudge.DataEngine.CallInterface.CommHelp;
using LdtJudge.DataEngine.Model.DataModel.DataParseStorage;
using System.Collections.Generic;

namespace LdtJudge.DataEngine.Data.DataParseStorage
{
    /// <summary>
    /// 案件数据存储数据层
    /// </summary>
    public class DAL_An_anjiancunchu
    {
        private IFreeSql FreeSql = FreeSQLHelp.GetFreeSQL("Ldt_DataParseStorage");
        public DAL_An_anjiancunchu()
        {}
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="anjid">条件</param>
        /// <returns></returns>
        public List<An_anjiancunchu> GetList(string anjianid)
        {
            return FreeSql.Select<An_anjiancunchu>().Where(a => a.Anjianid == anjianid).ToList();
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="anjid">条件</param>
        /// <param name="cunchuleixing">数据存储类型</param>
        /// <returns></returns>
        public List<An_anjiancunchu> GetList(string anjianid,string cunchuleixing)
        {
            return FreeSql.Select<An_anjiancunchu>().Where(a => a.Anjianid == anjianid && a.Cunchuleixing == cunchuleixing).ToList();
        }
        /// <summary>
        /// 判断当前类型的存储是否存在
        /// </summary>
        /// <param name="anjianid">案件ID</param>
        /// <param name="cunchuleixing">存储类型</param>
        /// <returns></returns>
        public An_anjiancunchu Exists(string anjianid,string cunchuleixing,string anyouid)
        {
            return FreeSql.Select<An_anjiancunchu>().Where(a => a.Anjianid == anjianid && a.Cunchuleixing==cunchuleixing && a.Anyouid==anyouid)?.First();
        }

        /// <summary>
        /// 添加案件数据存储记录
        /// </summary>
        /// <param name="model">案件数据存储模型</param>
        /// <returns></returns>
        public int Insert(An_anjiancunchu model)
        {
            string sql= FreeSql.Insert<An_anjiancunchu>(model).ToSql();
            return FreeSql.Insert<An_anjiancunchu>(model).ExecuteAffrows();
        }

        /// <summary>
        /// 更新案件数据存储记录
        /// </summary>
        /// <param name="model">案件数据存储模型</param>
        /// <returns></returns>
        public int Update(An_anjiancunchu model)
        {
            return FreeSql.Update<An_anjiancunchu>(model).SetSourceIgnore(model, col => col == null).ExecuteAffrows();
        }

        /// <summary>
        /// 更新文件内容
        /// </summary>
        /// <param name="id"></param>
        /// <param name="wenjianid"></param>
        /// <returns></returns>
        public int Update(string id,string wenjianid)
        {
            return FreeSql.Update<An_anjiancunchu>().Set(a => a.Wenjianid, wenjianid).Where(a => a.Anjiancunchuid == id).ExecuteAffrows();
        }
    }
}
